package database;

import java.util.ArrayList;
import java.util.Hashtable;

import addEmployeeTransaction.Employee;

public class InMemoryPayrollDatabase implements PayrollDatabase {
	private static Hashtable<Integer, Employee> employees = new Hashtable<Integer, Employee>();
	private static Hashtable<Integer, Employee> unionMembers = new Hashtable<Integer, Employee>();
	private static InMemoryPayrollDatabase db;

	private InMemoryPayrollDatabase() {
		
	}

	public static InMemoryPayrollDatabase getInstance() {
		if (db == null) {
			db = new InMemoryPayrollDatabase();
		}
		return db;
	}

	public void addEmployee(Employee employee) {
		employees.put(employee.getEmpId(), employee);
	}

	public Employee getEmployee(int id) {
		return (Employee) employees.get(id);
	}

	public void deleteEmployee(int id) {
		employees.remove(id);
	}

	public void addUnionMember(int id, Employee e) {
		unionMembers.put(id, e);
	}

	public Employee getUnionMember(int id) {
		return (Employee) unionMembers.get(id);
	}

	public void removeUnionMember(int memberId) {
		unionMembers.remove(memberId);
	}

	public ArrayList<Integer> getAllEmployeeIds() {
		return new ArrayList<Integer>(employees.keySet());
	}

	public ArrayList<Employee> getAllEmployees() {
		return new ArrayList<Employee>(employees.values());
	}

	public void clear() {
		employees.clear();
		unionMembers.clear();
	}
}
